package nels4561;

import spacewar2.actions.MoveAction;
import spacewar2.objects.Ship;
import spacewar2.simulator.Toroidal2DPhysics;
import spacewar2.utilities.Movement;
import spacewar2.utilities.Position;
import spacewar2.utilities.Vector2D;
/**
 * Made this custom action class to accomodate the fact
 * that we are using an Artificial Neural Network to move.
 * @author Michael
 *
 */
public class NNAction extends MoveAction{

	/**
	 * The angular acceleration
	 */
	private double rotation;
	/**
	 * The translational acceleration
	 */
	private Vector2D vector;
	/**
	 * Is our movement finished?
	 */
	private boolean isFinished;
	/**
	 * Allowable error in the target error before you say it is there
	 */
	public static double TARGET_REACHED_ERROR = 2.0;
	/**
	 * The location of our current target
	 */
	private static Position targetLocation;
	
	/**
	 * The constructor
	 * @param rot
	 * @param vect
	 * @param target
	 */
	public NNAction(double rot, Vector2D vect, Position target)
	{
		rotation = rot;
		vector = vect;
		isFinished = false;
		targetLocation = target;
	}
	
	/**
	 * Gets the movement. All is pre-calculated by the NN
	 */
	@Override
	public Movement getMovement(Toroidal2DPhysics space, Ship ship) {
		Movement mov = new Movement();
		
		mov.setAngularAccleration(rotation);
		
		mov.setTranslationalAcceleration(vector);
		
		if (space.findShortestDistance(targetLocation, ship.getPosition()) < TARGET_REACHED_ERROR)
		{
			isFinished = true;
		}
		
		return mov;
	}

	/**
	 * Is our movement finished?
	 */
	@Override
	public boolean isMovementFinished(Toroidal2DPhysics space) {
		return isFinished;
	}

}
